// 蜂窝蜜造平台生成代码，此文件只生成一次，不需要添加到 .beeignore

package com.fowo.api.service.impl;

import cn.hutool.core.util.StrUtil;
import com.fowo.api.model.adjustment.order.AdjustmentOrderVo;
import com.fowo.api.model.adjustment.order.product.AdjustmentOrderProductItemVo;
import org.springframework.stereotype.Service;

/**
 * 调整单 服务实现类
 */
@Service
public class AdjustmentOrderServiceImpl
  extends AdjustmentOrderBaseServiceImpl {

    /**
     * 更新所有子表
     * @param model 调整单
     */
    protected void updateAllChilds(AdjustmentOrderVo model) throws Exception {
        if (model.getProductLists() != null) {
            if(model.getType().equals("1")){ //换标调整 校验原店铺＋原FNSKU 是否等于 新店铺+新FNSKU
                for(AdjustmentOrderProductItemVo itemVo : model.getProductLists()){
                    if(StrUtil.equals(String.valueOf(itemVo.getShop()),String.valueOf(itemVo.getNewShop()))
                            && StrUtil.equals(String.valueOf(itemVo.getFnsku()),String.valueOf(itemVo.getNewFnsku()))
                ){
                        StringBuilder sb = new StringBuilder();
                        sb.append("产品【").append(itemVo.getSku()).append("】的原店铺+原FNSKU与新店铺+新FNSKU不能一致");
                        throw new Exception(sb.toString());
                    }
                }
            }
            adjustmentOrderProductService.saveAllByParentAdjustmentOrder(
                    model.getId(),
                    model.getProductLists()
            );
        }
    }
}
